const promisic = function (func) {
  return function (params = {}) {
    return new Promise((resolve, reject) => {
      const args = Object.assign(params, {
        success: (res) => {
          resolve(res);
        },
        fail: (error) => {
          reject(error);
        },
      });
      func(args);
    });
  };
};
// 组合算法
const combination = function (arr, size) {
  var r = [];
  function _(t, a, n) {
    if (n === 0) {
      r[r.length] = t;
      return;
    }
    for (var i = 0, l = a.length - n; i <= l; i++) {
      var b = t.slice();
      b.push(a[i]);
      _(b, a.slice(i + 1), n - 1);
    }
  }
  _([], arr, size);
  return r;
};
// 快速排序
const quickSort = function (arr) {
  if (arr.length <= 1) {
    return arr;
  }
  const pivot = arr[0]; // 选取基准值
  const left = [];
  const right = [];
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] < pivot) {
      left.push(arr[i]);
    } else {
      right.push(arr[i]);
    }
  }
  return quickSort(left).concat(pivot, quickSort(right)); // 递归排序左右两部分
};
export { promisic, combination, quickSort };
